package testpackageone; import java.applet.*; import java.awt.*; import java.awt.event.*; /** * Insert the type's description here. * Creation date: (07/23/2000 1:00:12 PM) * @author: Keith Chambers */ public class CalcApplet extends Applet implements KeyListener, MouseListener, WindowListener { private Label ivjLabel1 = null; private Panel ivjPanel1 = null; private TextField ivjTextField1 = null; private Button ivjButton1 = null; IvjEventHandler ivjEventHandler = new IvjEventHandler(); private Label ivjLabel2 = null; private TextField ivjTotal = null; class IvjEventHandler implements java.awt.event.MouseListener { public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getSource() == CalcApplet.this.getButton1()) connPtoP1SetTarget(); }; public void mouseEntered(java.awt.event.MouseEvent e) {}; public void mouseExited(java.awt.event.MouseEvent e) {}; public void mousePressed(java.awt.event.MouseEvent e) {}; public void mouseReleased(java.awt.event.MouseEvent e) {}; }; /** * Insert the method's description here. * Creation date: (07/23/2000 2:09:27 PM) */ public void calc1() { String y = getTextField1().getText(); Integer x = Integer.valueOf(y); int z = x.intValue(); if( z < 75) { setTotal("0"); } if( (z > 74) && (z < 100)) { setTotal("2"); } if( (z > 99) && (z < 150)) { setTotal("5"); } if( (z > 149) && (z < 200)) { setTotal("7"); } if( (z > 199) && (z < 250)) { setTotal("10"); } if( (z > 249) && (z < 300)) { setTotal("12"); } if( z > 299 ) { setTotal("Get real!"); } } /** * connPtoP1SetTarget: (Button1.this <--> Total.text) */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void connPtoP1SetTarget() { /* Set the target from the source */ try { //getTotal().setText(String.valueOf(getButton1())); calc1(); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {3} // user code end handleException(ivjExc); } } /** * Cleans up whatever resources are being held. If the applet is active * it is stopped. * * @see #init * @see #start * @see #stop */ public void destroy() { super.destroy(); // insert code to release resources here } /** * Returns information about this applet. * @return a string of information about this applet */ public String getAppletInfo() { return "CalcApplet\n" + "\n" + "Insert the type's description here.\n" + "Creation date: (07/23/2000 1:00:09 PM)\n" + "@author: Keith Chambers\n" + ""; } /** * Return the Button1 property value. * @return java.awt.Button */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.Button getButton1() { if (ivjButton1 == null) { try { ivjButton1 = new java.awt.Button(); ivjButton1.setName("Button1"); ivjButton1.setBounds(179, 102, 56, 23); ivjButton1.setLabel("Calculate"); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjButton1; } /** * Return the Label1 property value. * @return java.awt.Label */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.Label getLabel1() { if (ivjLabel1 == null) { try { ivjLabel1 = new java.awt.Label(); ivjLabel1.setName("Label1"); ivjLabel1.setAlignment(java.awt.Label.RIGHT); ivjLabel1.setText("Yards"); ivjLabel1.setBounds(123, 23, 49, 23); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjLabel1; } /** * Return the Label2 property value. * @return java.awt.Label */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.Label getLabel2() { if (ivjLabel2 == null) { try { ivjLabel2 = new java.awt.Label(); ivjLabel2.setName("Label2"); ivjLabel2.setAlignment(java.awt.Label.RIGHT); ivjLabel2.setText("Total"); ivjLabel2.setBounds(120, 165, 52, 23); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjLabel2; } /** * Return the Panel1 property value. * @return java.awt.Panel */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.Panel getPanel1() { if (ivjPanel1 == null) { try { ivjPanel1 = new java.awt.Panel(); ivjPanel1.setName("Panel1"); ivjPanel1.setLayout(null); ivjPanel1.setBackground(java.awt.Color.blue); ivjPanel1.setBounds(2, 4, 426, 240); getPanel1().add(getTextField1(), getTextField1().getName()); getPanel1().add(getLabel1(), getLabel1().getName()); getPanel1().add(getTotal(), getTotal().getName()); getPanel1().add(getButton1(), getButton1().getName()); getPanel1().add(getLabel2(), getLabel2().getName()); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjPanel1; } /** * Return the TextField1 property value. * @return java.awt.TextField */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.TextField getTextField1() { if (ivjTextField1 == null) { try { ivjTextField1 = new java.awt.TextField(); ivjTextField1.setName("TextField1"); //ivjTextField1.setText("0"); ivjTextField1.setBackground(java.awt.Color.white); ivjTextField1.setBounds(179, 23, 64, 23); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjTextField1; } /** * Return the Total property value. * @return java.awt.TextField */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.TextField getTotal() { if (ivjTotal == null) { try { ivjTotal = new java.awt.TextField(); ivjTotal.setName("Total"); ivjTotal.setBounds(179, 164, 70, 23); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } System.out.println(String.valueOf(getTextField1().getText())); return ivjTotal; } /** * Return the Total property value. * @return java.awt.TextField */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private java.awt.TextField getTotal(TextField TextField1) { if (ivjTotal == null) { try { ivjTotal = new java.awt.TextField(); ivjTotal.setName("Total"); ivjTotal.setBounds(179, 164, 70, 23); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } System.out.println(String.valueOf(getTextField1().getText())); return ivjTotal; } /** * Called whenever the part throws an exception. * @param exception java.lang.Throwable */ private void handleException(java.lang.Throwable exception) { /* Uncomment the following lines to print uncaught exceptions to stdout */ // System.out.println("--------- UNCAUGHT EXCEPTION ---------"); // exception.printStackTrace(System.out); } /** * Initializes the applet. */ public void init() { try { super.init(); setName("CalcApplet"); setLayout(null); setSize(426, 240); add(getPanel1(), getPanel1().getName()); initConnections(); // user code begin {1} // user code end } catch (java.lang.Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } /** * Initializes connections * @exception java.lang.Exception The exception description. */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void initConnections() throws java.lang.Exception { // user code begin {1} // user code end getButton1().addMouseListener(ivjEventHandler); connPtoP1SetTarget(); } /** * Called when a key has been pressed. * @param e the received event */ public void keyPressed(KeyEvent e) { System.out.println("keyPressed"); } /** * Called when a key has been released. * @param e the received event */ public void keyReleased(KeyEvent e) { System.out.println("keyReleased"); } /** * Called when a key has been typed. * @param e the received event */ public void keyTyped(KeyEvent e) { System.out.println("keyTyped"); } /** * Starts the applet when it is run as an application * @param args an array of command-line arguments */ public static void main(java.lang.String[] args) { CalcApplet applet = new CalcApplet(); java.awt.Frame frame = new java.awt.Frame("Applet"); frame.addWindowListener(applet); frame.add("Center", applet); frame.setSize(350, 250); frame.show(); applet.init(); applet.start(); } /** * Called when the mouse has been clicked. * @param e the received event */ public void mouseClicked(MouseEvent e) { System.out.println("mouseClicked"); } /** * Called when the mouse has entered a window. * @param e the received event */ public void mouseEntered(MouseEvent e) { System.out.println("mouseEntered"); } /** * Called when the mouse has exited a window. * @param e the received event */ public void mouseExited(MouseEvent e) { System.out.println("mouseExited"); } /** * Called when a mouse button has been pressed. * @param e the received event */ public void mousePressed(MouseEvent e) { System.out.println("mousePressed"); } /** * Called when a mouse button has been released. * @param e the received event */ public void mouseReleased(MouseEvent e) { System.out.println("mouseReleased"); } /** * Paints the applet. * If the applet does not need to be painted (e.g. if it is only a container for other * awt components) then this method can be safely removed. * * @param g the specified Graphics window * @see #update */ public void paint(Graphics g) { super.paint(g); // insert code to paint the applet here } /** * Insert the method's description here. * Creation date: (07/23/2000 2:03:50 PM) */ public void setTotal() { ivjTotal.setText(String.valueOf(getTextField1().getText())); } /** * Insert the method's description here. * Creation date: (07/23/2000 2:03:50 PM) */ public void setTotal(String input) { ivjTotal.setText(input); //ivjTotal.setText(String.valueOf(getTextField1().getText())); } /** * Called to start the applet. You never need to call this method * directly, it is called when the applet's document is visited. * @see #init * @see #stop * @see #destroy */ public void start() { super.start(); // insert any code to be run when the applet starts here } /** * Called to stop the applet. It is called when the applet's document is * no longer on the screen. It is guaranteed to be called before destroy() * is called. You never need to call this method directly. * @see #init * @see #start * @see #destroy */ public void stop() { super.stop(); // insert any code to be run when the applet is stopped here } /** * Invoked when a window is activated. * @param e the received event */ public void windowActivated(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } /** * Invoked when a window has been closed. * @param e the received event */ public void windowClosed(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } /** * Invoked when a window is in the process of being closed. * The close operation can be overridden at this point. * @param e the received event */ public void windowClosing(WindowEvent e) { // The window is being closed. Shut down the system. System.exit(0); } /** * Invoked when a window is deactivated. * @param e the received event */ public void windowDeactivated(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } /** * Invoked when a window is de-iconified. * @param e the received event */ public void windowDeiconified(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } /** * Invoked when a window is iconified. * @param e the received event */ public void windowIconified(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } /** * Invoked when a window has been opened. * @param e the received event */ public void windowOpened(WindowEvent e) { // Do nothing. // This method is required to comply with the WindowListener interface. } }